home *** CD-ROM | disk | FTP | other *** search
/ Collection of Tools & Utilities / Collection of Tools and Utilities.iso / dskut / reform16.zip / REFORMAT.IN4 < prev    next >
Text File  |  1987-05-22  |  12KB  |  228 lines

  1. {REFORMAT.IN4
  2.  Fast Write routine.
  3.  This does only a modicum of "flicker control" for slow or color
  4.  video cards.  Other versions are available for that if you just HAVE
  5.  to have such a thing.  Remember, REFORMAT is NOT a video-oriented utility.
  6.  If you have a weird video setup that doesn't permit direct write
  7.  to video memory, there's lots of "generic" code to use the regular
  8.  Turbo Pascal WRITE or WRITELN instructions.
  9.  Toad Hall.
  10. }
  11.  
  12. PROCEDURE WriteF(col,row : INTEGER; S : Line);
  13.   {Fast direct screen memory writing utility.
  14.    Permits x/y positioning anywhere on the screen, centering
  15.    at any y coordinate, line clearing (whole line or a specified
  16.    x coordinate), and line filling (whole line or a specified
  17.    x coordinate).
  18.    Special rules:
  19.      IF the first character of the string has an ASCII value above 127,
  20.      WriteF will assume this is a repeating character and fill a whole line
  21.      with that character.  Ignores rest of string (if it exists).
  22.      Naturally, if you send an ASCII 32+127, this will blank a line!
  23.      Filling starts at x coord, of course.
  24.  
  25.      IF the x coordinate is 0, WriteF will center the string according to
  26.      the current window size (the global variable width).
  27.  
  28.      IF the y coordinate is 0, WriteF will use the global variable toadY
  29.      as the current y coordinate (in the current window) and write this
  30.      line there.  toadY will be incremented.
  31.  
  32.      IF the y coordinate is NOT 0, WriteF will write at y, and will update
  33.      the global toadY to that coordinate.  toadY will NOT be incremented.
  34.  
  35.      IF we are filling, toadY will NOT increment.
  36.  
  37.    Toad Hall.
  38.   }
  39.   BEGIN
  40.     InLine(
  41.    $1E             {    push    DS            ;actual start of code}
  42.   /$06             {    push    ES            ;might as well save this
  43.                                                too}
  44.   /$8A/$96/>COL    {    mov     DL,>col[BP]   ;desired column}
  45.   /$8A/$A6/>ROW    {    mov     AH,>row[BP]   ;desired row}
  46.   /$08/$E4         {    or      AH,AH         ;zero?}
  47.   /$75/$04         {    jne     W2            ; nope, got a row val}
  48.   /$8A/$26/>TOADY  {    mov     AH,[>toadY]   ; 0, so make it toadY}
  49.                    {W2:}
  50.   /$88/$E6         {    mov     DH,AH         ;we use it here}
  51.  
  52.   /$8A/$2E/>WIDTH  {    mov     CH,[>width]   ;get global width variable}
  53.                    {;point ES:SI to the string (relative to stack, of
  54.                      course)}
  55.   /$8D/$BE/>S      {    lea     DI,>S[BP]     ;ES:SI = string vector}
  56.   /$57             {    push    DI}
  57.   /$5E             {    pop     SI           ;gonna use for source later}
  58.   /$36             {    SS:}
  59.   /$8A/$0C         {    mov     CL,[SI]       ;get str length into CX}
  60.   /$16             {    push    SS            ;the string var segment}
  61.   /$07             {    pop     ES            ;ES=SS}
  62.  
  63.   /$46             {    inc     SI            ;bump past str length}
  64.   /$47             {    inc     DI            ;here too}
  65.                    {;test to see if a clear or fill.}
  66.                    {;indicated by first string char being >127.}
  67.  
  68.   /$31/$C0         {    xor     AX,AX         ;clear a fill flag}
  69.   /$50             {    push    AX}
  70.   /$88/$F4         {    mov     AH,DH         ;get row back}
  71.   /$FE/$C4         {    inc     AH            ;assume we incr toadY}
  72.   /$26             {    ES:}
  73.   /$8A/$04         {    mov     AL,[SI]       ;get first char}
  74.   /$3C/$80         {    cmp     AL,128        ;is hi bit set?}
  75.   /$72/$12         {    jb      W3Y           ;nope, do centering test}
  76.  
  77.   /$88/$E9         {    mov     CL,CH         ;length=window width}
  78.   /$28/$D1         {    sub     CL,DL         ;minus col offset}
  79.   /$3C/$A0         {    cmp     AL,$A0        ;is it a hi-bit space?}
  80.   /$75/$08         {    jne     W3B           ; nope}
  81.   /$FE/$C1         {    inc     CL}
  82.   /$B0/$20         {    mov     AL,$20        ; yep, make it so}
  83.   /$8A/$26/>TOADY  {    mov     AH,[>toadY]   ;insure toadY doesn't change}
  84.                    {;must clear the old AX on the stack (0's, remember?)}
  85.                    {;and save our new value for the screen fill.}
  86.                    {W3B:}
  87.   /$5B             {    pop     BX            ;remove the zero fillflag}
  88.   /$50             {    push    AX            ;save fillchar}
  89.                    {W3Y:}
  90.   /$88/$26/>TOADY  {    mov     [>toadY],AH   ;post updated toadY}
  91.   /$08/$D2         {    or      DL,DL         ;0 = column=centering?}
  92.   /$75/$14         {    jne     W3Z           ; nope}
  93.                    {;centering a string, compute left margin offset.}
  94.   /$B2/$01         {    mov     DL,1          ;assume adjusted left margin}
  95.   /$88/$E8         {    mov     AL,CH         ;legal width}
  96.   /$28/$C8         {    sub     AL,CL         ;left over to justify}
  97.   /$76/$0C         {    jbe     W3Z           ;<= 0 left over}
  98.   /$78/$0A         {    js      W3Z  ;new}
  99.  
  100.   /$3C/$01         {    cmp     AL,1          ;just 1 left?}
  101.   /$74/$06         {    je      W3Z           ;yep, start at left margin}
  102.   /$04/$02         {    add     AL,2          ;fixes centering for text}
  103.   /$D0/$E8         {    shr     AL,1          ;divide in half}
  104.   /$88/$C2         {    mov     DL,AL         ;make THAT the col value}
  105.                    {;writing at col, protect right window margin}
  106.                    {W3Z:}
  107.   /$31/$C0         {    xor     AX,AX}
  108.   /$88/$C8         {    mov     AL,CL         ;string length}
  109.   /$00/$D0         {    add     AL,DL         ;add in col offset}
  110.   /$38/$E8         {    cmp     AL,CH         ;subtract scr width}
  111.   /$76/$08         {    jbe     W4            ; fine, <=}
  112.   /$88/$E8         {    mov     AL,CH         ; bad, make width - col}
  113.   /$28/$D0         {    sub     AL,DL}
  114.   /$FE/$C0         {    inc     AL            ;adjust for subtract}
  115.   /$88/$C1         {    mov     CL,AL}
  116.  
  117.                    {W4:}
  118.   /$FE/$CE         {    dec     DH}
  119.   /$FE/$CA         {    dec     DL            ;and col to 0..79}
  120.   /$02/$36/>WTOP   {    add     DH,[>wTop]    ;add in window Y coord
  121.                                                      offset}
  122.   /$02/$16/>WLEFT  {    add     DL,[>wLeft]   ;add in window left offset}
  123.   /$30/$ED         {    xor     CH,CH         ;clear to just length in
  124.                                                lsb}
  125.   /$88/$F0         {    mov     AL,DH         ;get the row value}
  126.   /$B3/$50         {    mov     BL,$50        ;fiddle for scrn absolute}
  127.   /$F6/$E3         {    mul     BL            ;rows * 90}
  128.   /$29/$DB         {    sub     BX,BX         ;clear msb}
  129.   /$88/$D3         {    mov     BL,DL         ;col for lsb}
  130.   /$01/$D8         {    add     AX,BX         ;add them}
  131.   /$01/$C0         {    add     AX,AX         ;*2}
  132.   /$89/$C7         {    mov     DI,AX         ;ES:DI=screen offset}
  133.   /$00/$CA         {    add     DL,CL         ;add str length for cursor psn}
  134.  
  135.   /$B4/$0F         {    mov     AH,15         ;get cur video mode}
  136.   /$CD/$10         {    int     $10           ;cur video page returned in
  137.                                                BH}
  138.   /$88/$C3         {    mov     BL,AL         ;save current mode in BL}
  139.   /$58             {    POP     AX            ;get fillchar-flag back}
  140.   /$50             {    PUSH    AX            ;save again}
  141.   /$08/$C0         {    OR      AL,AL         ;0 means no special char}
  142.   /$74/$02         {    je      W4A           ; no special char/clreol}
  143.   /$28/$CA         {    sub     DL,CL         ;force back to col}
  144.                    {W4A:}
  145.   /$53             {    push    BX            ;save page, mode}
  146.                    {;stack now has page/mode, fillchar-flag}
  147.   /$B4/$02         {    mov     AH,2          ;set cursor psn svc}
  148.   /$CD/$10         {    int     $10           ;ROM-BIOS video}
  149.   /$5B             {    pop     BX            ;restore page/mode}
  150.  
  151.   /$58             {    pop     AX            ;restore fillchar-flag in AL}
  152.                    {;stack clear}
  153.   /$8A/$26/>COLOR  {    mov     AH,[>color]   ;here's the attribute}
  154.                    {;might as well do this anyway, tho not needed if}
  155.